{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ">原文地址 https://blog.csdn.net/weixin_38727369/article/details/80927132?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task\n",
    "\n",
    "全部测试可用，如果有问题，请检查你的 gstreamer 是否安装了相应的插件。  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 屏幕录制\n",
    "\n",
    "gst-launch-1.0 ximagesrc remote=1 use-damage=0 ! video/x-raw,framerate=25/1 ! videoconvert  ! vp8enc ! matroskamux ! filesink location=test.mkv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 网络地址\n",
    "rtsp/rtmp\n",
    "\n",
    "- gst-launch-1.0 playbin uri=rtmp://58.200.131.2:1935/livetv/hunantv\n",
    "\n",
    "HTTP播放源\n",
    "- gst-launch-1.0 playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm\n",
    " \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## TI 3730 dvsdk\n",
    "\n",
    "板子上：  \n",
    "gst-launch -v v4l2src device=\"/dev/video7\" always-copy=FALSE ! ffmpegcolorspace ! 'video/x-raw-yuv,width=640,height=480,format=(fourcc)UYVY' ! TIVidenc1 codecName=h264enc engineName=codecServer contiguousInputFrame=TRUE ! rtph264pay pt=96 ! udpsink  host=192.168.3.3 port=5000  \n",
    "gst-launch -v udpsrc port=12000 caps=\"application/x-rtp\" ! rtph264depay ! ffdec_h264 ! xvimagesink  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## jpeg encode\n",
    "gst-launch v4l2src  ! ffmpegcolorspace ! ffmpegcolorspace ! 'video/x-raw-yuv,width=640,height=480,format=(fourcc)UYVY' ! jpegenc ! multipartmux ! tcpserversink host=127.0.0.1 port=5000  \n",
    "gst-launch-1.0 v4l2src device=\"/dev/video0\"  ! ffmpegcolorspace ! 'video/x-raw-yuv,width=640,height=480,format=(fourcc)UYVY' ! jpegenc ! multipartmux ! tcpserversink host=127.0.0.1 port=5000  \n",
    "\n",
    "gst-launch-1.0 tcpclientsrc host=127.0.0.1 port=5000 ! multipartdemux ! jpegdec ! autovideosink  \n",
    "\n",
    "gst-launch tcpclientsrc host=127.0.0.1 port=5000 ! multipartdemux ! jpegdec ! xvimagesink  \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## h264 no protocol\n",
    "\n",
    "gst-launch v4l2src device=\"/dev/video1\"  ! ffmpegcolorspace ! 'video/x-raw-yuv,width=640,height=480,format=(fourcc)UYVY' ! h264enc ! multipartmux ! tcpserversink host=127.0.0.1 port=5000  \n",
    "\n",
    "gst-launch tcpclientsrc host=127.0.0.1 port=5000 ! multipartdemux ! h264dec ! autovideosink  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video1 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240,framerate=(fraction)15' ! autovideoconvert ! x264enc  tune=\"zerolatency\" threads=4  ! mpegtsmux  ! udpsink host=127.0.0.1 port=12345 ts-offset=0 \n",
    "\n",
    "gst-launch-1.0 udpsrc port=12345 ! tsdemux ! video/x-h264 !  h264parse ! avdec_h264 ! autovideosink  sync=false  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## gstreamer packet protocol\n",
    "gst-launch v4l2src device=\"/dev/video1\"   ! ffmpegcolorspace ! 'video/x-raw-yuv,width=640,height=480,format=(fourcc)UYVY' ! gdppay ! tcpserversink host=127.0.0.1 port=5000  \n",
    "\n",
    "gst-launch v4l2src device=\"/dev/video1\"   ! ffmpegcolorspace ! 'video/x-raw-yuv,width=320,height=240,format=(fourcc)UYVY,framerate=(fraction)20/1' ! gdppay ! tcpserversink host=127.0.0.1 port=5000  \n",
    "\n",
    "gst-launch tcpclientsrc host=127.0.0.1 port=5000 ! gdpdepay   ! xvimagesink  \n",
    "\n",
    "gst-launch-0.10 v4l2src device=\"/dev/video0\"   ! ffmpegcolorspace ! 'video/x-raw-yuv,width=320,height=240,format=(fourcc)UYVY,framerate=(fraction)5/1' ! gdppay ! tcpclientsink host=127.0.0.1 port=5000  \n",
    "\n",
    "gst-launch-0.10 tcpserversrc port=5000 ! gdpdepay ! ffmpegcolorspace ! xvimagesink  \n",
    "\n",
    "gst-launch-0.10 v4l2src device=\"/dev/video0\"   ! ffmpegcolorspace ! gdppay ! tcpclientsink host=127.0.0.1 port=5000  \n",
    "\n",
    "gst-launch-0.10 tcpserversrc port=5000 ! gdpdepay ! ffmpegcolorspace ! xvimagesink  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=\"/dev/video0\"   ! videoconvert ! gdppay ! tcpclientsink host=localhost port=5000 \n",
    "\n",
    "gst-launch-1.0 tcpserversrc port=5000 ! gdpdepay ! videoconvert ! xvimagesink  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video0 norm=255 ! videoconvert ! 'video/x-raw,width=640,height=480' ! autovideoconvert ! x264enc  tune=\"zerolatency\" threads=4  ! gdppay ! tcpclientsink host=localhost port=5000  \n",
    "\n",
    "gst-launch-1.0 tcpserversrc port=5000   !  gdpdepay ! h264parse ! avdec_h264 ! xvimagesink --gst-debug=*:2  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## filesrc\n",
    "\n",
    "gst-launch-1.0 filesrc location=./music.mp3 ! mad  ! audioconvert ! audioresample ! pulsesink --gst-debug=*:2  \n",
    "\n",
    "gst-launch-1.0 filesrc location=./music.mp3 ! mad ! pulsesink --gst-debug=*:2  \n",
    "\n",
    "gst-launch-1.0 filesrc location=/home/songwater/Cproject/x265/x265/build/linux/720.hevc blocksize=1024 !  libde265dec mode=raw  ! queue ! autovideosink  \n",
    "\n",
    "gst-launch-1.0 playbin uri=file:///home/songwater/Cproject/gstreamer/gstreamer-lde265/examples/spreedmovie.mkv --gst-debug=*:3  \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## rtp x264\n",
    "gst-launch-1.0 v4l2src device=/dev/video0 norm=255 ! videoconvert ! 'video/x-raw,width=640,height=480' ! autovideoconvert ! x264enc  tune=\"zerolatency\" threads=1  ! rtph264pay config-interval=2  ! udpsink host=127.0.0.1 port=12345  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video0 norm=255 ! videoconvert ! 'video/x-raw,width=640,height=480' ! autovideoconvert ! x264enc  tune=\"zerolatency\" threads=4  ! rtph264pay  ! udpsink host=127.0.0.1 port=12345  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video1 norm=255 ! videoconvert ! 'video/x-raw,width=1280,height=720' ! autovideoconvert ! x264enc  tune=\"zerolatency\" threads=4  ! rtph264pay  ! udpsink host=127.0.0.1 port=12345  \n",
    "\n",
    "gst-launch-1.0 udpsrc port=12345 ! application/x-rtp, payload=96  ! rtpjitterbuffer ! rtph264depay ! h264parse ! avdec_h264 ! xvimagesink --gst-debug=*:4  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## direct play\n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video0 norm=255 ! videoconvert ! 'video/x-raw,width=640,height=480' ! autovideoconvert ! x264enc  tune=\"zerolatency\" threads=4  ! video/x-h264 !   h264parse ! avdec_h264 ! xvimagesink sync=false  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video0 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240' ! autovideoconvert ! x265enc tune=\"zerolatency\"  !  libde265dec mode=raw ! queue ! autovideosink  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video0 norm=255 ! autovideoconvert ! 'video/x-raw,width=320,height=240,format=(string){\"I420\"},framerate=(fraction)15' !  x265enc tune=\"zerolatency\"  !  libde265dec mode=raw ! queue ! xvimagesink sync=false  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video1 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240' ! autovideoconvert ! x265enc option-string=\"fps=15/1:bitrate=64\" !  libde265dec mode=raw ! queue ! autovideosink sync=false \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video1 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240,framerate=(fraction)15'  ! autovideoconvert ! x265enc tune=\"zerolatency\"  option-string=\"crf=28\" ! rtph265pay ! rtph265depay ! video/x-h265 ! h265parse ! avdec_h265  ! xvimagesink sync=false  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## capture  to file\n",
    "gst-launch-1.0 v4l2src device=/dev/video0 norm=255 ! autovideoconvert ! 'video/x-raw,width=320,height=240,format=(string){\"I420\"},framerate=(fraction)15' !  filesink location=cap.yuv  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video1 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240,framerate=(fraction)15'  ! autovideoconvert ! x265enc  ! filesink location=cap1.hevc\n",
    "\n",
    "## file to file x265 encode\n",
    "gst-launch-1.0 filesrc location=/home/songwater/Cproject/x265/x265/build/linux/cap.yuv  !  x265enc  ! filesink location=cap1.hevc  \n",
    "\n",
    "\n",
    "## x265 no protocol\n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video0 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240,framerate=(fraction)15'  ! autovideoconvert ! x265enc  tune=\"zerolatency\"   !  udpsink host=127.0.0.1 port=12345 ts-offset=0  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video1 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240,framerate=(fraction)15'  ! autovideoconvert ! x265enc  tune=\"zerolatency\"  option-string=\"fps=15/1:bitrate=64\" !  udpsink host=127.0.0.1 port=12345 ts-offset=0 --gst-debug=v4l2allocator:5  \n",
    "\n",
    "gst-launch-1.0 udpsrc port=12345   !  libde265dec mode=raw   ! xvimagesink  sync=false  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video1 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240,framerate=(fraction)15'  ! autovideoconvert ! x265enc tune=\"fastdecode\"  speed-preset=\"medium\" option-string=\"crf=28\" !  udpsink host=127.0.0.1 port=12345 ts-offset=0 --gst-debug=x265enc:4 \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video0 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240,framerate=(fraction)15'  ! autovideoconvert ! x265enc tune=\"zerolatency\"  option-string=\"bitrate=64\" !  udpsink host=192.168.1.107 port=12345 ts-offset=0 --gst-debug=x265enc:4  \n",
    "\n",
    "gst-launch-1.0 udpsrc port=12345 do-timestamp=false !  libde265dec mode=raw   ! xvimagesink   --gst-debug=*:2  \n",
    "\n",
    "## rtph265\n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video1 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240,framerate=(fraction)15'  ! autovideoconvert ! x265enc  ! rtph265pay ! udpsink host=127.0.0.1 port=12345  \n",
    "\n",
    "gst-launch-1.0 v4l2src device=/dev/video1 norm=255 ! videoconvert ! 'video/x-raw,width=320,height=240,framerate=(fraction)15'  ! autovideoconvert ! x265enc tune=\"zerolatency\"  option-string=\"bitrate=64\"  ! rtph265pay ! udpsink host=127.0.0.1 port=12345  \n",
    "\n",
    "gst-launch-1.0 udpsrc port=12345  ! application/x-rtp,payload=96 ! rtph265depay ! video/x-h265 ! h265parse ! avdec_h265  ! xvimagesink "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
